import Mock from 'mockjs';

//登录
Mock.mock('/login', 'post', (options) => {
    const { username } = JSON.parse(options.body);
    let token
    if (username === 'admin') {
        token='admin'
    } else {
        token='user'
    }
    return {
        code: 200,
        token
    }
})

//获取权限列表
Mock.mock('/getPermissions', 'post', (options) => {
    const { token } = JSON.parse(options.body);
  let permissions = [
      {
          path: 'home',
          name: 'Home',
          meta:{title:'首页',icon:'dashboard',isShow:true}
      },
       {
          path: 'echarts',
          name: 'Echarts',
          meta:{title:'图表',icon:'dashboard',isShow:true}
      },
      {
          path: 'user',
          name: 'User',
          meta:{title:'用户列表',icon:'dashboard',isShow:true}
      },
      {
          path: 'permission',
          name: 'Permission',
          meta:{title:'按钮权限',icon:'dashboard',isShow:true}
      },
      {
          path: 'richtext',
          name: 'Richtext',
          meta:{title:'富文本',icon:'dashboard',isShow:true}
      },
      {
          path: 'loadsh',
          name: 'Loadsh',
          meta:{title:'loadsh',icon:'dashboard',isShow:true}
      },
      {
          path: 'dialog',
          name: 'Dialog',
          meta:{title:'自定义弹框',icon:'dashboard',isShow:true}
      },
        {
          path: 'upload',
          name: 'Upload',
          meta:{title:'图片上传',icon:'dashboard',isShow:true}
      },
         {
          path: 'usesvg',
          name: 'Usesvg',
          meta:{title:'svg',icon:'dashboard',isShow:true}
    },
  ]
  if (token === 'admin'){
          permissions.push({
          path: 'setting',
          name: 'Setting',
          meta:{title:'系统设置',icon:'dashboard',isShow:true}
        })
  }
  return {
      code: 200,
      permissions,
      message: '获取权限列表成功'
  }
})